<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/19
 * Time: 16:51

 * 订单类
 */

namespace app\console\controller;
use think\Build;
use think\Db;
use think\Request;
use think\Url;
use think\Session;


class SalesmanOrder
{
    /**
     * @return array|mixed|\think\response\View
     * 订单列表
     */
    public function index()
    {
        $where = [];
        if(session('auding_status') == 1){
            $where['m.id'] = ['eq',Session::get('manage_id')];
        }
        $param = Request::instance()->param();
        if(!empty($param['salesman_id'])) $where['mdr.manage_id'] = ['eq',$param['salesman_id']];
        if (!empty($param['interval_timer'])) {
            $interval_timer = explode('/', $param['interval_timer']);
            $where['mdr.create_time'] = ['between', [$interval_timer[0], $interval_timer[1]]];
        }else{
			$six_begin_time = date('Y-m-d 00:00:00',time());
			$six_end_time = date('Y-m-d 23:59:59',time());
			$where['mdr.create_time'] = ['between', [$six_begin_time, $six_end_time]];
		}
        $data = Db::name('member_distribution_records mdr')
            ->join('manager m','mdr.manage_id = m.id','left')
            ->join('member mem','mdr.member_id = mem.id','left')
            ->join('share_member sm','sm.member_id = mem.id')
            ->where($where)
            ->field('mdr.manage_id,m.nickname manage_name,mem.username me,mdr.*,sm.manage_id md')
            ->order('mdr.create_time desc')
            ->paginate(10,false,['query' => $param]);

        $new_data = $data->toArray();
        foreach ($new_data['data'] as &$item){
            if(\session('auding_status') == 1){
                $item['me'] = hideStr($item['me'],3,4);
            }
            $parent_id = Db::name('salesman')->where('manage_id',$item['manage_id'])->value('parent_id');

            $s = [1 => '线上订单', 2 => '线下订单', 3 => '门店订单', 4 => '普通订单','0' => '-'];
            $item['finance_order_text'] =$s[Db::name('order')->where('order_number|shop_order_number',$item['order_number'])->value('order_online')] ;
            $item['parent_name'] = Db::name('manager')->where('id',$parent_id)->value('nickname');
            $item['share_manage'] = Db::name('manager')->where('id',$item['md'])->value('nickname');
                $item['goods_title'] = '';
                if($item['order_type']==1){
                    //根据订单号查询订单下面商品
                    $order_goods = Db::name('order_goods')
                        ->where('order_number|shop_order_number',$item['order_number'])
                        ->select();
                    $str = '';
                    foreach ($order_goods as $value){
                        $str .= $value['title'].'/';
                    }
                    $new_str=substr($str,0,strlen($str)-1);
                    $item['goods_title'] = $new_str;
                }
                if($item['order_type'] == 3){
                    $gift = Db::name('order')->where('order_number',$item['order_number'])->find();
                    $item['goods_title'] = $gift['gift_title'];
                }
            if($item['order_type'] == 2){
                $service = Db::name('order o')
                    ->join('shop s','o.shop_id = s.id','left')
                    ->where('o.order_number',$item['order_number'])
                    ->field('o.*')
                    ->find();
                $item['goods_title'] = Db::name('single')->where('id',$service['single_parent_id'])->value('cat_name') .' > '.Db::name('single')->where('id',$service['single_id'])->value('cat_name');
            }
            if(session('role_id') != 1) {
                $item['me'] = hideStr($item['me'], 1, 6);

            }
        }

        $order_count = Db::name('member_distribution_records mdr')
            ->join('manager m','mdr.manage_id = m.id','left')
            ->where($where)
            ->field('m.username manage_name,mem.username,mdr.*')
            ->join('member mem','mdr.member_id = mem.id','left')->count();
       // dump(1);
        $member_count = Db::name('member_distribution_records mdr')
            ->join('manager m','mdr.manage_id = m.id','left')
            ->where($where)
            ->field('m.username manage_name,mem.username,mdr.*')
            ->join('member mem','mdr.member_id = mem.id','left')->count('mdr.member_id');
        $price['total_price'] = $price['price'] = $price['per'] = 0;
        $price = Db::name('member_distribution_records mdr')
            ->join('manager m','mdr.manage_id = m.id','left')
            ->where($where)
            ->field('m.username manage_name,mem.username,mdr.*,sum(price) price,sum(mdr.per) per,sum(price+mdr.per+mdr.single_per) total_price,sum(single_per) single_per')
            ->join('member mem','mdr.member_id = mem.id','left')->find();//分销金额


        $all_date = Db::name('salesman s')
            ->join('manager m','s.manage_id = m.id','left')
            ->field('m.username,m.create_time,s.*,m.id,m.telephone')
            ->select()->toArray();
        $parent_id = 0;
        if(session('auding_status') == 1){
            $where['m.id'] = ['eq',Session::get('manage_id')];
        }
        if(session('auding_status') == 1){
            $parent_id = Session::get('manage_id');
        }

        $son_data = count(getMenuTree1($all_date,$parent_id));
        $w = [];
        $auding_status = Db::name('manager m')->where('m.id',session('manage_id'))->join('auth_group ag','m.level = ag.id')->value('auding_status');
        if($auding_status == 1){
            $parent_id = session('manage_id');
            $w['s.manage_id'] = ['eq',\session('manage_id')];
        }

        $salesman = Db::name('salesman s')
            ->join('manager m','s.manage_id = m.id','left')
            ->field('m.username,m.nickname,m.create_time,s.*,m.id,m.telephone')
            ->where('m.level',4)
            ->select()->toArray();
        $salesman = getMenuTree2($salesman,0);

        return view('', ['data' => $data,'new_data'=>$new_data,'order_count' => $order_count,'total_price' => $price['total_price'],'price' => $price['price'],'per' => $price['per'],'single_per' => $price['single_per'],'member_count' => $member_count,'son_data' => $son_data,'salesman' => $salesman]);
    }
    public function card2(){
        $param = Request::instance()->param();
        $where = [];
        if(session('auding_status') == 1){
            $where['yewuyuan_id'] = ['eq',Session::get('manage_id')];
        }
        if (!empty($param['interval_timer'])) {
            $interval_timer = explode('/', $param['interval_timer']);
            $where['gc.create_time'] = ['between', [$interval_timer[0], $interval_timer[1]]];
        }
        if (!empty($param['gift_id'])) $where['coupon_id'] = ['eq', $param['gift_id']];
        if (!empty($param['status'])) $where['gc.status'] = ['eq', $param['status']];
        if(!empty($param['salesman_id'])) $where['yewuyuan_id'] = ['eq',$param['salesman_id']];
        $data = Db::name('coupon_card gc')
            ->join('coupon g','gc.gift_id = g.id')
            ->join('manager m','gc.yewuyuan_id = m.id','left')
            ->join('member mb','gc.member_id = mb.id','left')
            ->join('order o','o.order_number = gc.order_number','left')
            ->where($where)
            ->field('gc.*,g.title,m.nickname,g.id g_id,o.order_number,mb.username,o.car_number')
            ->order(['gc.id' => 'desc'])->paginate(10, false, ['query' => $param]);

        $salesman = Db::name('salesman s')
            ->join('manager m','s.manage_id = m.id','left')
            ->field('m.username,m.nickname,m.create_time,s.*,m.id,m.telephone')
            ->where('m.level',4)
            ->select()->toArray();
        $salesman = getMenuTree2($salesman,0);
        $where2['status'] = ['eq', 1];

        $where2['card_type'] = ['eq',2];
        $gift = Db::name('coupon')->where($where2)->select();

        $gift1 = Db::name('coupon_card gc')
            ->join('coupon g','gc.gift_id = g.id')
            ->join('manager m','gc.yewuyuan_id = m.id')
            ->join('member mb','gc.member_id = mb.id','left')
            ->join('order o','o.order_number = gc.order_number','left')
            ->where($where)
            ->where('gc.status',1)
            ->count();
        $gift2 = Db::name('coupon_card gc')
            ->join('coupon g','gc.gift_id = g.id')
            ->join('manager m','gc.yewuyuan_id = m.id')
            ->join('member mb','gc.member_id = mb.id','left')
            ->join('order o','o.order_number = gc.order_number','left')
            ->where($where)
            ->where('gc.status',2)
            ->count();
        $gift3 = Db::name('coupon_card gc')
            ->join('coupon g','gc.gift_id = g.id')
            ->join('manager m','gc.yewuyuan_id = m.id')
            ->join('member mb','gc.member_id = mb.id','left')
            ->join('order o','o.order_number = gc.order_number','left')
            ->where($where)
            ->where('gc.status',3)
            ->count();
        return view('',['data' => $data,'salesman' => $salesman,'gift' => $gift,'gift_count1' => $gift1,'gift_count2' => $gift2,'gift_count3' => $gift3]);
    }
    public function card($pages = 10){

        $param = Request::instance()->param();
        $where = [];
        if(session('auding_status') == 1){
            $where['yewuyuan_id'] = ['eq',Session::get('manage_id')];
        }
        if (!empty($param['interval_timer'])) {
            $interval_timer = explode('/', $param['interval_timer']);
            $where['gc.create_time'] = ['between', [$interval_timer[0], $interval_timer[1]]];
			//var_dump($interval_timer);
        }

        if (!empty($param['gift_id'])) $where['gc.gift_id'] = ['eq', $param['gift_id']];
        if (!empty($param['status'])) $where['gc.status'] = ['eq', $param['status']];
        if(!empty($param['salesman_id'])) $where['yewuyuan_id'] = ['eq',$param['salesman_id']];
       
        $data = Db::name('gift_card gc')
            ->join('gift g','gc.gift_id = g.id','left')
            ->join('manager m','gc.yewuyuan_id = m.id','left')
            ->join('member mb','gc.member_id = mb.id','left')
            ->join('order o','o.order_number = gc.order_number','left')
            ->where($where)
            ->field('gc.*,g.title,m.nickname,gc.id g_id,o.order_number,o.username,o.car_number,o.amount,o.gift_title')
            ->order(['gc.create_time' => 'desc'])->paginate($pages, false, ['query' => $param]);

        $salesman = Db::name('salesman s')
            ->join('manager m','s.manage_id = m.id','left')
            ->field('m.username,m.nickname,m.create_time,s.*,m.id,m.telephone')
            ->where('m.level',4)
            ->select()->toArray();
        $salesman = getMenuTree2($salesman,0);
        $where2['status'] = ['eq', 1];
        $where2['is_delete'] = ['eq', 1];
        $where2['card_type'] = ['eq',2];
        $gift = Db::name('gift')->where($where2)->select();

        $gift1 = Db::name('gift_card gc')
            ->join('gift g','gc.gift_id = g.id','left')
            ->join('manager m','gc.yewuyuan_id = m.id','left')
            ->join('member mb','gc.member_id = mb.id','left')
            ->join('order o','o.order_number = gc.order_number','left')
            ->where($where)
            ->where('gc.status',1)
            ->count();
        $gift2 = Db::name('gift_card gc')
            ->join('gift g','gc.gift_id = g.id','left')
            ->join('manager m','gc.yewuyuan_id = m.id','left')
            ->join('member mb','gc.member_id = mb.id','left')
            ->join('order o','o.order_number = gc.order_number','left')
            ->where($where)
            ->where('gc.status',2)
            ->count();
        $gift3 = Db::name('gift_card gc')
            ->join('gift g','gc.gift_id = g.id','left')
            ->join('manager m','gc.yewuyuan_id = m.id','left')
            ->join('member mb','gc.member_id = mb.id','left')
            ->join('order o','o.order_number = gc.order_number','left')
            ->where($where)
            ->where('gc.status',3)
            ->count();

        if($pages != 10){
            $user_data[] = ['ID', '业务员', '礼包名称', '会员卡卡号', '激活码', '会员卡状态', '订单号', '订单金额', '手机号', '车牌号', '激活时间', '创建时间'];
            foreach ($data as $v) {
                if($v['status']  == 1){
                    $v['status'] = '等待激活';
                }
                if($v['status']  == 2){
                    $v['status'] = '已激活';
                }
                if($v['status']  == 3){
                    $v['status'] = '禁止激活';
                }
                $user_data[] = [$v['g_id'], $v['nickname'], $v['title'], $v['card_num'], $v['card_password'], $v['status'], $v['order_number'], $v['amount'], "\t" . $v['username'] . "\t", $v['car_number'],$v['jihuo_time'],$v['create_time']];
            }

            $this->create_xls($user_data,'业务员会员卡导出');
        }
        return view('',['data' => $data,'salesman' => $salesman,'gift' => $gift,'gift_count1' => $gift1,'gift_count2' => $gift2,'gift_count3' => $gift3]);
    }
    public function create_xls($data,$filename='礼包使用情况.xls'){
        ini_set('max_execution_time', '0');

        import('phpoffice.phpexcel.Classes.PHPExcel', EXTEND_PATH, '.php');

        $filename=str_replace('.xls', '', $filename).'.xls';
        $phpexcel = new \PHPExcel();
        $phpexcel->getProperties()
            ->setCreator("Maarten Balliauw")
            ->setLastModifiedBy("Maarten Balliauw")
            ->setTitle("Office 2007 XLSX Test Document")
            ->setSubject("Office 2007 XLSX Test Document")
            ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
            ->setKeywords("office 2007 openxml php")
            ->setCategory("Test result file");
        $phpexcel->getActiveSheet()->fromArray($data);
        $phpexcel->getActiveSheet()->setTitle('业务员会员卡导出');

        $phpexcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header("Content-Disposition: attachment;filename=$filename");
        header('Cache-Control: max-age=0');
        header('Cache-Control: max-age=1');
        header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
        header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header ('Pragma: public'); // HTTP/1.0
        $objwriter = \PHPExcel_IOFactory::createWriter($phpexcel, 'Excel5');
        $objwriter->save('php://output');
        exit;
    }

    public function daochu(){
        $where = [];
        if(session('auding_status') == 1){
            $where['m.id'] = ['eq',Session::get('manage_id')];
        }
        $param = Request::instance()->param();
        if(!empty($param['salesman_id'])) $where['mdr.manage_id'] = ['eq',$param['salesman_id']];
        if (!empty($param['interval_timer'])) {
            $interval_timer = explode('/', $param['interval_timer']);
            $where['mdr.create_time'] = ['between', [$interval_timer[0], $interval_timer[1]]];
        }
        $data = Db::name('member_distribution_records mdr')
            ->join('manager m','mdr.manage_id = m.id','left')
            ->join('member mem','mdr.member_id = mem.id','left')
            ->join('share_member sm','sm.member_id = mem.id')
            ->where($where)
            ->field('mdr.manage_id,m.username manage_name,mem.username me,mdr.*,sm.manage_id md')
            ->order('mdr.create_time desc')
            ->paginate(10000);

        $new_data = $data->toArray();
        foreach ($new_data['data'] as &$item){
            if(\session('auding_status') == 1){
                $item['me'] = hideStr($item['me'],3,4);
            }
            $item['share_manage'] = Db::name('manager')->where('id',$item['md'])->value('username');
            $item['goods_title'] = '';
            if($item['order_type']==1){
                //根据订单号查询订单下面商品
                $order_goods = Db::name('order_goods')
                    ->where('order_number|shop_order_number',$item['order_number'])
                    ->select();
                $str = '';
                foreach ($order_goods as $value){
                    $str .= $value['title'].'/';
                }
                $new_str=substr($str,0,strlen($str)-1);
                $item['goods_title'] = $new_str;
            }
            if($item['order_type'] == 3){
                $gift = Db::name('order')->where('order_number',$item['order_number'])->find();
                $item['goods_title'] = $gift['gift_title'];
            }
            if($item['order_type'] == 2){
                $service = Db::name('order o')
                    ->join('shop s','o.shop_id = s.id','left')
                    ->where('o.order_number',$item['order_number'])
                    ->field('o.*')
                    ->find();
                $item['goods_title'] = Db::name('single')->where('id',$service['single_parent_id'])->value('cat_name') .' > '.Db::name('single')->where('id',$service['single_id'])->value('cat_name');
            }
            if(session('role_id') != 1) {
                $item['me'] = hideStr($item['me'], 1, 6);

            }

        }

        $this->push_coupon($new_data['data'],'业务员业绩记录');
    }
    public function push_coupon($data,$name = 'Excel')
    {
        set_time_limit(0);
        ini_set('memory_limit', '1024M');
        error_reporting(E_ALL);
        date_default_timezone_set('Asia/Shanghai');

        import('phpoffice.phpexcel.Classes.PHPExcel', EXTEND_PATH, '.php');
        $objPHPExcel = new \PHPExcel();

        /*以下是一些设置 ，什么作者  标题啊之类的*/
        $objPHPExcel->getProperties()->setCreator("管理员")
            ->setLastModifiedBy("管理员")
            ->setTitle("电话本导出")
            ->setSubject("数据EXCEL导出")
            ->setDescription("备份数据")
            ->setKeywords("excel")
            ->setCategory("result file");
        $objPHPExcel->setActiveSheetIndex(0)
            //Excel的第A列，shop_name是你查出数组的键值，下面以此类推
            ->setCellValue('A1', '业务员')
            ->setCellValue('B1', '下级业务员')
            ->setCellValue('C1', '下单用户')
            ->setCellValue('D1', '订单编号')
            ->setCellValue('E1', '消费时间')
            ->setCellValue('F1', '消费项目')
            ->setCellValue('G1', '消费金额')
            ->setCellValue('H1', '佣金')
            ->setCellValue('I1', '业务员直销金额')
            ->setCellValue('J1', '业务员单销金额')
        ;
        $sheet1 = [];

        for ($x = 0; $x < count($sheet1); $x++) {
            $objPHPExcel->getActiveSheet()->getStyle($sheet1[$x] . '1')->applyFromArray(
                array(
                    'font'      => array(
                        'bold' => true
                    ),
                    'alignment' => array(
                        'horizontal' =>
                            \PHPExcel_Style_Alignment::HORIZONTAL_CENTER
                    )
                )
            );
        }

        /*以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改*/

        $n = 0;
        foreach ($data as $v) {

            $num = $n + 2;
            $objPHPExcel->setActiveSheetIndex(0)
                //Excel的第A列，shop_name是你查出数组的键值，下面以此类推
                ->setCellValue('A' . $num, $v['manage_name'])
                ->setCellValue('B' . $num, $v['share_manage'])
                ->setCellValue('C' . $num, "\t".$v['me']."\t")
                ->setCellValue('D' . $num, $v['order_number'])
                ->setCellValue('E' . $num, $v['create_time'])
                ->setCellValue('F' . $num, $v['goods_title'])
                ->setCellValue('G' . $num, $v['amount'])
                ->setCellValue('H' . $num, $v['price'])
                ->setCellValue('I' . $num, $v['per'])
                ->setCellValue('J' . $num, $v['single_per'])
            ;


            $n++;
        }

        $objPHPExcel->getActiveSheet(0)->setTitle('业务员业绩记录');
        $objPHPExcel->setActiveSheetIndex(0);

        ob_end_clean();
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;charset=utf-8;filename="' . $name . '.xls"');
        header('Cache-Control: max-age=0');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
        exit;
    }

    public function push_coupon2($data,$name = 'Excel')
    {
        set_time_limit(0);
        ini_set('memory_limit', '1024M');
        error_reporting(E_ALL);
        date_default_timezone_set('Asia/Shanghai');

        import('phpoffice.phpexcel.Classes.PHPExcel', EXTEND_PATH, '.php');
        $objPHPExcel = new \PHPExcel();

        /*以下是一些设置 ，什么作者  标题啊之类的*/
        $objPHPExcel->getProperties()->setCreator("管理员")
            ->setLastModifiedBy("管理员")
            ->setTitle("电话本导出")
            ->setSubject("数据EXCEL导出")
            ->setDescription("备份数据")
            ->setKeywords("excel")
            ->setCategory("result file");
        $objPHPExcel->setActiveSheetIndex(0)
            //Excel的第A列，shop_name是你查出数组的键值，下面以此类推
            ->setCellValue('A1', '业务员')
            ->setCellValue('B1', '下级业务员')
            ->setCellValue('C1', '下单用户')
            ->setCellValue('D1', '订单编号')
            ->setCellValue('E1', '消费时间')
            ->setCellValue('F1', '消费项目')
            ->setCellValue('G1', '消费金额')
            ->setCellValue('H1', '佣金')
            ->setCellValue('I1', '业务员直销金额')
            ->setCellValue('J1', '业务员单销金额')
        ;
        $sheet1 = [];

        for ($x = 0; $x < count($sheet1); $x++) {
            $objPHPExcel->getActiveSheet()->getStyle($sheet1[$x] . '1')->applyFromArray(
                array(
                    'font'      => array(
                        'bold' => true
                    ),
                    'alignment' => array(
                        'horizontal' =>
                            \PHPExcel_Style_Alignment::HORIZONTAL_CENTER
                    )
                )
            );
        }

        /*以下就是对处理Excel里的数据， 横着取数据，主要是这一步，其他基本都不要改*/

        $n = 0;
        foreach ($data as $v) {

            $num = $n + 2;
            $objPHPExcel->setActiveSheetIndex(0)
                //Excel的第A列，shop_name是你查出数组的键值，下面以此类推
                ->setCellValue('A' . $num, $v['manage_name'])
                ->setCellValue('B' . $num, $v['share_manage'])
                ->setCellValue('C' . $num, "\t".$v['me']."\t")
                ->setCellValue('D' . $num, $v['order_number'])
                ->setCellValue('E' . $num, $v['create_time'])
                ->setCellValue('F' . $num, $v['goods_title'])
                ->setCellValue('G' . $num, $v['amount'])
                ->setCellValue('H' . $num, $v['price'])
                ->setCellValue('I' . $num, $v['per'])
                ->setCellValue('J' . $num, $v['single_per'])
            ;
            

            $n++;
        }

        $objPHPExcel->getActiveSheet(0)->setTitle('业务员业绩记录');
        $objPHPExcel->setActiveSheetIndex(0);

        ob_end_clean();
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;charset=utf-8;filename="' . $name . '.xls"');
        header('Cache-Control: max-age=0');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
        exit;
    }

    /**
     * @param $id
     * 订单修改
     * 6已完成
     */
    public function update($id)
    {

        $param = Request::instance()->param();
        if (Request::instance()->isPost()) {
            $status = Db::name('order')->where('id',$id)->value('status');
            if ($status == 6) {
                $shop_id = Db::name('shop_create')->where('manage_id',Session::get('manage_id'))->value('shop_id');//当前创建的门店id;
                if(empty($shop_id)) fail('当前管理员不是门店管理员');
                $ret = Db::name('order')->where('id', $param['id'])->update(['status' => 6]);
                if ($ret !== false) {
                    $gift_records = Db::name('gift_records')->insert([
                        'order_id' => $id,
                        'content' => $param['content'],
                        'manage_id' => Session::get('manage_id'),
                        'shop_id' => 0,
                        'create_time' => date('Y-m-d H:i:s',time())
                    ]);
                    win('修改成功', Url::build('index'));
                }
            }
            if (isset($param['status']) && ($param['status'] == 11 || $param['status'] == 12)) {
                $ret = Db::name('order')->where('id', $param['id'])->update(['status' => $param['status']]);
                if ($ret !== false) {
                    $refund_ret = Db::name('order_refund')->where('order_id',$id)->update(['fail_explain' =>$param['fail_explain']]);
                    if($refund_ret !== false){
                        win('退款处理完毕', Url::build('index'));
                    }
                }
            }
        }
        $info = Db::name('order o')
            ->join('member m', 'o.member_id = m.id')
            ->join('shop s', 'o.shop_id = s.id','left')
            ->field('o.*,m.username,s.shop_title')
            ->where('o.id', $param['id'])
            ->find();
        if($info['status'] == 10 || $info['status'] == 11 || $info['status'] == 12){
            $info['refund_create_time'] = Db::name('order_refund')->where('order_id',$info['id'])->value('create_time');
        }
        $gift_records = Db::name('gift_records gr')->join('shop s','gr.shop_id = s.id')->field('gr.*,s.shop_title')->where('order_id',$id)->select();
        return view('', ['item' => $info,'gift_records' => $gift_records]);
    }

}